/**
 * File:Cache.java
 * Date:
 * <p>
 * 四川长虹网络科技有限责任公司 (智能应用研发部)© 版权所有
 */
package com.zigong.app.application;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import com.ruihang.generalibrary.utils.ListUtils;
import com.zigong.app.beans.CityServiceBean;
import com.zigong.app.beans.FocusColumn;
import com.zigong.app.beans.NewsItem;
import com.zigong.app.beans.UserInfoBean;

import java.util.ArrayList;
import java.util.List;


/**
 * 用于缓存静态数据。与用户无关
 */
public class Cache {
    private static Cache instance;
    private boolean networkConnected;//网络状态

    private String Province;//省份
    private String CurrentCity;//当前城市名
    private String CurrentCityCode;//当前城市Code

    private String versionName;//当前版本号
    private int versionCode;//当前版本编号

    private boolean isCityShow = false;//是否同步市州数据
    private boolean isStarted = false;//市州app是否已经唤起过了
    private String choosedCity = "";//切换市州的城市名
    private String choosedCityStUrl = "";//市州新闻中获取评论等动态接口的域名。
    private String choosedCityNewsUrl = "";//市州获取首页精选同步数据的JSon接口
    private String choosedCityTitle = "";//市州获取首页精选同步数据的title
    private String choosedCityIcon = "";//市州获取首页精选同步数据的icon

    private UserInfoBean userInfo;//用户积分等数据

    private List<CityServiceBean> serviceCityList;//服务模块配置的可用城市列表

    private String hotVideoUrl = "";//首页精选更多热门视频URL

    private boolean isStartAdClicked = false;//启动页的新闻链接是否被点击触发
    //缓存栏目数据
    private List<FocusColumn> fChannels = new ArrayList<>();

    private String currentChannelId;

    private boolean isHomeToAudio = false;//是否是从精选页面进入听广播

    private boolean isHomeGreateAdClosed = false;//精选底部广告是否关闭

    private boolean isRemindLogin = false;//是否提示过用户登录后查看新闻增加积分

    private boolean isCheckNet = false;//是否提示过4G网络播放问题

    private List<NewsItem> shortVideonList = new ArrayList<>();//短视频点击进入播放列表缓存的视频
    private boolean isUploadReb = false; //是否正在提交爆料
    private Cache() {
    }

    public static Cache getInstance() {
        if (null == instance) {
            instance = new Cache();
        }
        return instance;
    }

    public void initVersion(Context ctx) {
        try {
            PackageManager manager = ctx.getPackageManager();
            PackageInfo info = manager.getPackageInfo(ctx.getPackageName(), 0);
            versionName = info.versionName;
            versionCode = info.versionCode;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @return the networkConnected
     */
    public boolean isNetworkConnected() {
        return networkConnected;
    }

    /**
     * @param networkConnected the networkConnected to set
     */
    public void setNetworkConnected(boolean networkConnected) {
        this.networkConnected = networkConnected;
    }

    public String getProvince() {
        return Province;
    }

    public void setProvince(String province) {
        Province = province;
    }

    public String getCurrentCity() {
        return CurrentCity;
    }

    public void setCurrentCity(String currentCity) {
        CurrentCity = currentCity;
    }

    public String getCurrentCityCode() {
        return CurrentCityCode;
    }

    public void setCurrentCityCode(String currentCityCode) {
        CurrentCityCode = currentCityCode;
    }

    public String getVersionName() {
        return versionName;
    }

    public void setVersionName(String versionName) {
        this.versionName = versionName;
    }

    public int getVersionCode() {
        return versionCode;
    }

    public void setVersionCode(int versionCode) {
        this.versionCode = versionCode;
    }

    public boolean isCityShow() {
        return isCityShow;
    }

    public void setCityShow(boolean cityShow) {
        isCityShow = cityShow;
    }

    public boolean isStarted() {
        return isStarted;
    }

    public void setStarted(boolean started) {
        isStarted = started;
    }

    public String getChoosedCity() {
        return choosedCity;
    }

    public void setChoosedCity(String choosedCity) {
        this.choosedCity = choosedCity;
    }

    public String getChoosedCityStUrl() {
        return choosedCityStUrl;
    }

    public void setChoosedCityStUrl(String choosedCityStUrl) {
        this.choosedCityStUrl = choosedCityStUrl;
    }

    public String getChoosedCityNewsUrl() {
        return choosedCityNewsUrl;
    }

    public void setChoosedCityNewsUrl(String choosedCityNewsUrl) {
        this.choosedCityNewsUrl = choosedCityNewsUrl;
    }

    public String getChoosedCityTitle() {
        return choosedCityTitle;
    }

    public void setChoosedCityTitle(String choosedCityTitle) {
        this.choosedCityTitle = choosedCityTitle;
    }

    public String getChoosedCityIcon() {
        return choosedCityIcon;
    }

    public void setChoosedCityIcon(String choosedCityIcon) {
        this.choosedCityIcon = choosedCityIcon;
    }

    public UserInfoBean getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(UserInfoBean userInfo) {
        this.userInfo = userInfo;
    }

    public List<CityServiceBean> getServiceCityList() {
        return serviceCityList;
    }

    public void setServiceCityList(List<CityServiceBean> serviceCityList) {
        this.serviceCityList = serviceCityList;
    }

    public String getHotVideoUrl() {
        return hotVideoUrl;
    }

    public void setHotVideoUrl(String hotVideoUrl) {
        this.hotVideoUrl = hotVideoUrl;
    }

    public boolean isStartAdClicked() {
        return isStartAdClicked;
    }

    public void setStartAdClicked(boolean startAdClicked) {
        isStartAdClicked = startAdClicked;
    }

    public boolean isHomeToAudio() {
        return isHomeToAudio;
    }

    public void setHomeToAudio(boolean homeToAudio) {
        isHomeToAudio = homeToAudio;
    }

    public boolean isHomeGreateAdClosed() {
        return isHomeGreateAdClosed;
    }

    public void setHomeGreateAdClosed(boolean homeGreateAdClosed) {
        isHomeGreateAdClosed = homeGreateAdClosed;
    }

    public boolean isRemindLogin() {
        return isRemindLogin;
    }

    public void setRemindLogin(boolean remindLogin) {
        isRemindLogin = remindLogin;
    }

    public boolean isCheckNet() {
        return isCheckNet;
    }

    public void setCheckNet(boolean checkNet) {
        isCheckNet = checkNet;
    }

    public List<NewsItem> getShortVideonList() {
        return shortVideonList;
    }

    public void setShortVideonList(List<NewsItem> shortVideonList) {
        if(null!=shortVideonList) {
            this.shortVideonList = shortVideonList;
        }else{
            this.shortVideonList.clear();
        }
    }

    public boolean isUploadReb() {
        return isUploadReb;
    }

    public void setUploadReb(boolean uploadReb) {
        isUploadReb = uploadReb;
    }

    /**
     * 主界面 不同模块间获取栏目ID （如专题）
     * @param name
     *  @param name
     * @return
     */
    public String getCurrentColumnId(String name,String name1 ){
        if (TextUtils.isEmpty(name)|| !ListUtils.isListValued(fChannels)) {
            return "";
        }else {
            for (int i = 0; i < fChannels.size(); i++) {
                if (fChannels.get(i).getChannelName().contains(name)||fChannels.get(i).getChannelName().contains(name1)) {
                    return ""+fChannels.get(i).getChannelId();
                }
            }
        }
        return "";
    }

    /**
     * 首页中 获取不同栏目的ID
     * @return
     */
    public String getCurrentChannelId() {
        return currentChannelId;
    }

    public void setCurrentChannelId(String currentChannelId) {
        this.currentChannelId = currentChannelId;

    }

    public List<FocusColumn> getfChannels() {
        return fChannels;
    }

    public void setfChannels(List<FocusColumn> list) {
        if(null==fChannels){
            fChannels = new ArrayList<>();
        }else{
            fChannels.clear();
        }
        fChannels.addAll(list);
    }
}
